﻿﻿﻿﻿using DeviceCommons.DeviceMessages.Models;
using System.Buffers;

namespace DeviceCommons.DeviceMessages.Abstractions
{
    public interface IMessageSerializer<T> : IMessagePayload<T> where T : IBase
    {
        Func<string, string>? EncryptFunc { get; set; }
        Func<byte[], byte[]>? CompressFunc { get; set; }

        void Serializer(ArrayBufferWriter<byte> writer);

        void Serializer(ArrayBufferWriter<byte> writer, T message);

        string Serializer(ArrayBufferWriter<byte> writer, T message, bool isCompress);

        string Serializer(ArrayBufferWriter<byte> writer, Action action, bool isEncrypt = false, bool isCompress = false);

        string Serializer(ArrayBufferWriter<byte> writer, Action action, bool isEncrypt, bool isCompress, string? encryptionPassword);

        string Serializer(ArrayBufferWriter<byte> writer, T message, bool isEncrypt = false, bool isCompress = false);

        string Serializer(ArrayBufferWriter<byte> writer, T message, bool isEncrypt, bool isCompress, string? encryptionPassword);

        Task SerializerAsync(ArrayBufferWriter<byte> writer, T message, CancellationToken cancellationToken = default);
        Task SerializerAsync(ArrayBufferWriter<byte> writer, CancellationToken cancellationToken = default);
        Task<string> SerializerAsync(ArrayBufferWriter<byte> writer, T message, bool isCompress, CancellationToken cancellationToken = default);
        Task<string> SerializerAsync(ArrayBufferWriter<byte> writer, T message, bool isEncrypt, bool isCompress, CancellationToken cancellationToken = default);
        Task<string> SerializerAsync(ArrayBufferWriter<byte> writer, T message, bool isEncrypt, bool isCompress, string? encryptionPassword, CancellationToken cancellationToken = default);
        Task<string> SerializerAsync(ArrayBufferWriter<byte> writer, bool isCompress, CancellationToken cancellationToken = default);
        Task<string> SerializerAsync(ArrayBufferWriter<byte> writer, bool isEncrypt, bool isCompress, CancellationToken cancellationToken = default);
    }
}
